<?php 

/**
 * Joomla! 1.5 component arts_curriculum
 * @package com_arts_curriculum
 * @author     Chris Borkowski {@link http://www.guggenheim.org}
 * @author     Created on 15 July-2010
 * @author    Modified on 16-July-2010

 **/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );


  /**
  * @package arts_curriculum
  */
	  class Arts_curriculumFrontHelper {
	
		function checkderivative2($file_name) {
	  	
	  	global $mainframe ;
	  	
	  	$check_file = JPATH_ROOT . DS . "images". DS ."content" . DS ."arts_curriculum". DS . "derivative2". DS .$file_name ;
	  	
		if (file_exists($check_file)) {
		return true;
		} else {

		//contants for size and quality
		$h_targ_w = 120;
		$v_targ_h = 120;
		$jpeg_quality = 100;
		
		// where the derivatives live 
		$uploads_path = JPATH_ROOT . DS . "images". DS ."content" . DS ."arts_curriculum". DS . "derivative1" ;
		// where the files will be placed
		$thumb_path = JPATH_ROOT . DS . "images". DS ."content" . DS ."arts_curriculum". DS . "derivative2" ;
		
		//get some info from image
		$image_stats = GetImageSize($uploads_path.'/'.$file_name);
		$imagewidth = $image_stats[0];
		$imageheight = $image_stats[1];

	
		//do math to determine height
		$ratio = ($imagewidth / $h_targ_w);
		$new_h = round($imageheight / $ratio);

		$src_img = imagecreatefromjpeg($uploads_path."/".$file_name);
		$dst_img = imagecreatetruecolor($h_targ_w,$new_h);
		
		imagecopyresampled($dst_img,$src_img,0,0,0,0,$h_targ_w,$new_h,imagesx($src_img),imagesy($src_img));
		imagejpeg($dst_img, $thumb_path."/".$file_name, $jpeg_quality);						
		imagedestroy($dst_img);
		
		}//end if
	
  
  
  	}//end function
	  
	  
	  
}//the end
